<template>
    <div id="tansverse-bar-two" ref="canvas" class="canvas-tansverse-bar" :style="{width: '100%', height: canHeight + 'vh'}"></div>
</template>

<script setup lang="ts">
import { defineProps, computed, onMounted } from 'vue'
import * as echarts from 'echarts/core';
import {
  TitleComponent,
  type TitleComponentOption,
  TooltipComponent,
  type TooltipComponentOption,
  GridComponent,
  type GridComponentOption,
  LegendComponent,
  type LegendComponentOption
} from 'echarts/components';
import { BarChart, type BarSeriesOption } from 'echarts/charts';
import { CanvasRenderer } from 'echarts/renderers';

echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  BarChart,
  CanvasRenderer
]);

type EChartsOption = echarts.ComposeOption<
  | TitleComponentOption
  | TooltipComponentOption
  | GridComponentOption
  | LegendComponentOption
  | BarSeriesOption
>;
const props = defineProps({
    canvasHeight: {
        type:Number,
        default: 300
    },
    data: {
        type: Object,
        default: () => { } 
    }
})
let canHeight = computed(() => { return props.canvasHeight })
onMounted(() => {
    var chartDom = document.getElementById('tansverse-bar-two')!;
    var myChart = echarts.init(chartDom);
    var option: EChartsOption;

    option = {
    title: {
        show: false,
        text: '数据来源'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
        type: 'shadow'
        }
    },
    legend: { show: false },
    grid: {
        top: 20,
        left: '3%',
        right: '10%',
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        show: false,
        type: 'value',
        boundaryGap: [0, 0.01],
        splitLine:{show:false, lineStyle:{color: '#445471'}},
    },
    yAxis: {
        type: 'category',
        data: props.data.xAxisDataList || ['Brazil', 'Indonesia', 'USA', 'India', 'China', 'World'],
        axisLine: { show: false },
        axisTick: { show: false },
    },
    series: [
        {
        name: '2011',
        type: 'bar',
        itemStyle: {
            color: {
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                    offset: 0, color: '#0599eb' // 0% 处的颜色
                }, {
                    offset: 1, color: '#67e9f7' // 100% 处的颜色
                }],
                global: false // 缺省为 false
            },
        },
        label: {
            show: true,
            color: '#fff',
            align: 'left'
        },
        emphasis: {
            focus: 'series'
        },
        data:  props.data.seriesDataList || [18203, 23489, 29034, 104970, 131744, 630230]
        }
    ]
    };

    option && myChart.setOption(option);
})
</script>

<style scope>
</style>
